/**
 * @Description:
 * @Author: CHEHSHUANG
 * @Date: 2019/1/23
 */
import React, {Component} from 'react';
import {Checkbox, Form,Input,Modal,Row} from "antd"

const FormItem = Form.Item;
const formLayout = {
    labelCol: {span: 6},
    wrapperCol: {span: 16}
}

class EditTenantModal extends Component {
    getFormValue = () => {
        let result = false;
        this.props.form.validateFieldsAndScroll((err, values) => {
            if (!err) {
                result = values;
                const {isEdit,editData} = this.props;
                if (isEdit&&editData) {
                    result.id = editData.id || null;
                }
            }
        });
        return result;
    }
    componentDidMount(){
        this.props.onRef && this.props.onRef(this);
    }
    render() {
        const {title, visible, onOk, onCancel,isEdit, editData,confirmLoading} = this.props;
        const {getFieldDecorator} = this.props.form;
        return (
            <Modal
                width={500}
                centered
                destroyOnClose={true}
                maskClosable={false}
                title={title}
                confirmLoading={confirmLoading}
                visible={visible}
                onCancel={onCancel}
                onOk={onOk}
            >
                <Form>
                    {
                        isEdit ?
                         <Row>
                           <FormItem
                             label={"代码"}
                             {...formLayout}
                           >
                             {getFieldDecorator('code', {
                               initialValue: editData && editData.code ? editData.code : "",
                               rules: [{required: false}]
                             })(
                               <Input disabled/>
                             )}
                           </FormItem>
                         </Row>
                          : null
                    }
                  <Row>
                    <FormItem
                      label={"名称"}
                      {...formLayout}
                    >
                      {getFieldDecorator('name', {
                        initialValue: isEdit && editData && editData.name ? editData.name : "",
                        rules: [{required: true, message: '请填写名称!'}]
                      })(
                        <Input placeholder={"请填写名称"}/>
                      )}
                    </FormItem>
                  </Row>
                    {
                      isEdit ?<Row>
                        <FormItem
                          label={"冻结"}
                          {...formLayout}
                        >
                          {getFieldDecorator('frozen', {
                            initialValue: editData ? editData.frozen : false,
                            valuePropName: "checked"
                          })(
                            <Checkbox/>
                          )}
                        </FormItem>
                      </Row>: null
                    }
                </Form>
            </Modal>
        );
    }
}

export default Form.create()(EditTenantModal);
